import { resolve } from 'path'

import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'


// 🔒 PPH专用端口锁定 - 禁止AI修改
const PPH_FRONTEND_PORT = 3010;

export default defineConfig({
  plugins: [
    vue(),
    VitePWA({
      registerType: 'autoUpdate',
      workbox: {
        globPatterns: ['**/*.{js,css,html,ico,png,svg}']
      },
      manifest: {
        name: 'PPH生产效率系统',
        short_name: 'PPH系统',
        description: 'PPH生产效率管理系统',
        theme_color: '#ffffff',
        icons: [
          {
            src: 'pwa-192x192.png',
            sizes: '192x192',
            type: 'image/png'
          }
        ]
      }
    }),
    // 端口防护插件
    {
      name: 'pph-port-guard',
      configureServer(server) {
        server.httpServer?.on('listening', () => {
          console.log(`🔒 PPH前端端口已锁定: ${PPH_FRONTEND_PORT}`);
          console.log(`⚠️  禁止修改此端口配置`);
        });
      },
    },
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
  },
  server: {
    port: PPH_FRONTEND_PORT,
    strictPort: true, // 端口被占用时直接报错，不自动切换
    host: '0.0.0.0', // 绑定到所有网络接口，允许局域网访问
    cors: true
  },
  preview: {
    port: PPH_FRONTEND_PORT,
    strictPort: true
  },
  build: {
    outDir: 'dist',
    sourcemap: true
  }
})
